package com.tc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    @Bean
    //封装线程池
    public ExecutorService createThreadPool(){
        return new ThreadPoolExecutor(
                10,//核心线程
                20,//最大线程
                60L,//临时线程存活时间
                TimeUnit.SECONDS,//时间单位
                new LinkedBlockingQueue<>(100),//工作队列
                new ThreadPoolExecutor.CallerRunsPolicy()//直接调用主线程执行任务
        );
    }
}
